package com.example.dormitorysystem.controller;


import com.example.dormitorysystem.common.aop.OperationLogAnnotation;
import com.example.dormitorysystem.entity.Rooms;
import com.example.dormitorysystem.service.RoomsService;
import com.example.dormitorysystem.utils.Response;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 吉吉王国组
 * @since 2022-11-26
 */
@RestController
@RequestMapping("")
public class RoomsController {

    @Resource
    private RoomsService roomsService;


    @GetMapping("/room/room")
    @OperationLogAnnotation(operModul = "房间信息模块", operType = "RoomInfo", operDesc = "读取房间信息")
    public Response getRoomInfo(@RequestParam(value = "id") String id, HttpServletRequest request) {

        Rooms room = roomsService.getRoomById(id);
        if (room == null) return Response.error().message("该寝室不参与寝室分配");
        HashMap<String, Object> res = new HashMap<>();
        res.put("name", room.getName());
        res.put("gender", room.getGender());
        res.put("describe", room.getDescribes());
        res.put("image_url", room.getImageUrl());
        res.put("building_id", room.getBuildingId());

        return Response.success().data(res);
    }
}

